package com.flash.BusinessParameters.controller;

import com.flash.BusinessParameters.entity.Broker;
import com.flash.BusinessParameters.entity.DealSeat;
import com.flash.BusinessParameters.service.BrokerService;
import com.flash.GlobalManagement.util.Dbutil;
import com.flash.GlobalManagement.util.TableIdUtil;
import com.flash.GlobalManagement.util.TableNameUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class BrokerController {
    @Resource
    BrokerService brokerService;

    @Resource
    Dbutil dbutil;

    @RequestMapping("/insert")
    public String insert(){
        return "addBroker";
    }

    @RequestMapping("/toBroker")
    public String toBroker(){
        return "broker";
    }

    @RequestMapping("/updateBrokers")
    public String updateBroker(){
        return "updateBroker";
    }

    /**
     * 条件查询全部
     * @param brokerName 名字
     * @param page
     * @param limit
     * code msg data count
     * @return
     */
    @RequestMapping("/selectBroker")
    @ResponseBody
    public Map selectBroker(String brokerName, int page, int limit){
        System.out.println("测试");
        HashMap map=new HashMap();
        System.out.println(brokerName);
        List<Broker> brokerList = brokerService.selectBrokerMap(brokerName, page, limit);
        int i = brokerService.selectCountBroker();
        System.out.println(brokerList);
        map.put("code",0);
        map.put("msg","");
        map.put("data",brokerList);
        map.put("count",i);
        return map;
    }

    /**
     * 增加
     * @param broker 实体类
     * @return
     */
    @RequestMapping("/insertBroker")
    @ResponseBody

    public String insertBroker(Broker broker){
        System.out.println("添加用户");
        broker.setBrokerId(dbutil.getMaxId2(TableIdUtil.BID,TableNameUtil.B));
        int i = brokerService.insertBroker(broker);
        System.out.println(i);
        if (i>0){
            return "ok";
        }else{
            return "no";
        }
    }

    /**
     * 删除
     * @param brokerId
     * @return
     */
    @RequestMapping("/deleteBroker")
    @ResponseBody
    public int deleteBroker(String brokerId){
        System.out.println("删除");
        int i = brokerService.deleteBroker(brokerId);
        System.out.println(i);
        return i;
    }

    /**
     * 修改
     * @param broker
     * @return
     */
    @RequestMapping("/updateBroker")
    @ResponseBody
    //修改
    public int updateBroker(Broker broker){
        System.out.println("这是修改");
        int i = brokerService.updateBroker(broker);
        System.out.println(i);
        return i;
    }
}
